﻿<%@ Page Language="C#" MasterPageFile="~/SimplePMTModal.Master" AutoEventWireup="true" CodeBehind="TaskView.aspx.cs" Inherits="SimplePMT.TaskView" %>
<asp:Content ID="Content1" runat="server" ContentPlaceHolderID="MainContent">
    <%= taskView %>
    </p>
    <script>
        var editNoteId = 0;
        var tmpId = '';
        var tmpSvnId = '';
        var df = document.taskForm;
        var sn = true;
        var selTab = 'notes';
        if (df.Title) {
            df.Title.focus();
        }
        function cancelEditNote() {
            document.getElementById('EditNoteForm').style.display = 'none';
        }
        
        function editNote(id) {
            editNoteId = id;
            
            document.getElementById('EditNoteForm').style.display = 'inline';
            SimplePMT.TaskView.GetEditTaskNote(id, function(response) {
                if (response.error != null) {
                    alert(response.error.Message);
                } else {
                    document.taskForm.EditNotes.value = response.value[0];
                    document.taskForm.EditHours.value = response.value[1];
                    document.taskForm.EditNoteDateTime.value = response.value[2];
                }
            });
            window.scrollBy(0,220);
        }
        
        function show(item) {
            document.getElementById('tabnotes').className = 'Tab';
            document.getElementById('tabattachments').className = 'Tab';
            document.getElementById('tabsvn').className = 'Tab';
            document.getElementById('tabrelease').className = 'Tab';
            document.getElementById('tab'+item).className = 'Tab-Over';
            
            document.getElementById('notes').style.display = 'none';
            document.getElementById('attachments').style.display = 'none';
            document.getElementById('svn').style.display = 'none';
            document.getElementById('release').style.display = 'none';
            document.getElementById(item).style.display = 'inline';
            
            
            selTab = 'tab'+ item;
            
            window.scrollBy(0,200);
        }
        
        function chkTab(io, tab) {
            io.className='Tab-Over';
        }
        
        function chkOutTab(io, tab) {
            if (tab != selTab) {
                io.className='Tab';
            }
        }
        function confirmDelete(id) {
            if (confirm('Are you sure you want to delete this task?')) {
                SimplePMT.TaskView.DeleteTask(id, function (response) {
                    alert('Task deleted successfully.');
                    pcid = <%= parentContainerId %>;
                    if (pcid > 0) {
                        top.reloadParentNode(<%= parentContainerId %>, top.document.img<%= parentContainerId %>);
                         top.win.close();
                    } else {
                        top.location.reload();
                    }
                });
            }
        }
        
        function showNote(id) {
            if (!sn) {
                tmpId = '';
                sn = true;
                document.getElementById(id).style.display = 'none';
            } else {
                //sn = false;
                if (tmpId != '') {
                    document.getElementById(tmpId).style.display = 'none';
                }
                tmpId = id;
                document.getElementById(id).style.display = 'inline';
                window.scrollBy(0,200);
            }
        }
        
        function showSvnCommit(id) {
            if (!sn) {
                tmpSvnId = '';
                sn = true;
                document.getElementById(id).style.display = 'none';
            } else {
                sn = false;
                if (tmpId != '') {
                    document.getElementById(tmpId).style.display = 'none';
                }
                tmpId = id;
                document.getElementById(id).style.display = 'inline';
                window.scrollBy(0,200);
            }
        }
        
        function showHideNoteForm(noteList, noteForm) {
            document.getElementById('noteList').style.display = noteList;
            document.getElementById('noteForm').style.display = noteForm;
            df.Notes.value = '';
            window.scrollBy(0,200); 
        }
        function noteComplete(io) {
            var noteList = 'inline';
            var noteForm = 'none';
            var btns = 'inline';
            var newNoteLink = 'inline';
                
            if (io.checked) {
                noteList = 'none';
                noteForm = 'inline';
                btns = 'none'
                newNoteLink = 'none';
            }
            document.getElementById('noteList').style.display = noteList;
            document.getElementById('noteForm').style.display = noteForm;
            document.getElementById('noteFormBtns').style.display = btns;
            document.getElementById('addNewNote').style.display = newNoteLink;
            window.scrollBy(0,200); 
            df.Notes.value = '';
        }
        
        function addNote(note, hours, date, io) {
            io.disabled = true;
            if (note == '') {
                alert('The note cannot be blank.');
                return;
            } else if (hours == '') {
                alert('Hours cannot be blank, enter 0 if no work was performed.');
                return;
            } else {
                SimplePMT.TaskView.AddTaskNote(<%= taskId %>, note, <%= memberId %>, hours, date, function (response) {
                    io.disabled = false;
                    if (response.value) {
                        showHideNoteForm('inline', 'none');
                        alert('Note added successfully.');
                        SimplePMT.TaskView.GetTaskNotes(<%= taskId %>, function (response) {
                            document.getElementById('noteList').innerHTML = '<table width=100%>'+ response.value +'</table>';
                        });
                    } else {
                        alert(response.error.Message);
                    }
                    
                });
            }
            
            
        }
        
        function updateNote(note, hours, date) {
            if (note == '') {
                alert('The note cannot be blank.');
                return;
            } else if (hours == '') {
                alert('Hours cannot be blank, enter 0 if no work was performed.');
                return;
            } else {
                SimplePMT.TaskView.UpdateTaskNote(<%= taskId %>, editNoteId, note, <%= memberId %>, hours, date, function (response) {
                    if (response.value) {
                        showHideNoteForm('inline', 'none');
                        alert('Note updated successfully.');
                        SimplePMT.TaskView.GetTaskNotes(<%= taskId %>, function (response) {
                            document.getElementById('noteList').innerHTML = '<table width=100%>'+ response.value +'</table>';
                        });
                        cancelEditNote();
                    } else {
                        alert(response.error.Message);
                    }
                });
            }
        }
        
        function saveTask(releaseId, taskStatus, taskContainerId, taskId, taskTypeId, taskTitle, taskDescription, createMemberId, hoursEstimated, hours, isComplete, note, priorityId, noteDate) {
            if (isComplete && note == '') {
                alert('If marking this task complete, the notes (and hours) cannot be left blank.');
            } else {
                actualComplexity = 0;
                estimatedComplexity = 0;
                assignedMemberId = 0;
                if (document.taskForm.AssignedMemberID) {
                    assignedMemberId = document.taskForm.AssignedMemberID.options[document.taskForm.AssignedMemberID.selectedIndex].value;
                } 
                if (document.taskForm.ComplexityActualID.options) {
                    actualComplexity = document.taskForm.ComplexityActualID.options[document.taskForm.ComplexityActualID.selectedIndex].value;
                } else if (document.taskForm.ComplexityActualID) {
                    actualComplexity = document.taskForm.ComplexityActualID.value;
                }
                if (document.taskForm.ComplexityEstimatedID.options) {
                    estimatedComplexity = document.taskForm.ComplexityEstimatedID.options[document.taskForm.ComplexityEstimatedID.selectedIndex].value;
                } else if (document.taskForm.ComplexityEstimatedID) {
                    estimatedComplexity = parseInt(document.taskForm.ComplexityEstimatedID.value);
                }
                
                SimplePMT.TaskView.SaveTask(releaseId, taskStatus, document.taskForm.DueDate.value, taskContainerId, taskId, taskTypeId, taskTitle, taskDescription, createMemberId, assignedMemberId, hoursEstimated, hours, estimatedComplexity, actualComplexity, isComplete, note, priorityId, noteDate, function (response) {
                    
                    if (response.error != null) {
                        alert(response.error.Message);
                        document.getElementById('saveButton').disabled = false;
                        //top.reloadParentNode(<%= parentContainerId %>, top.document.img<%= parentContainerId %>);
                        //top.win.close();
                    } else {
                        if (response.value[2] != '') {
                            alert(response.value[2]);
                        }
                        pcid = <%= parentContainerId %>;
                        if (pcid > 0 && top.project) {
                            top.reloadParentNode(<%= parentContainerId %>, top.document.img<%= parentContainerId %>);
                            top.win.close();
                        } else {
                            top.location.reload();
                        }
                    }
                    
                });
            }
        }
    </script>
</asp:Content>